<script type="text/javascript">
    function addChecked(sNode) {
        var index = sNode.selectedIndex;
        var option = sNode.options[index];
        option.selected = false;
        document.getElementById("checkedRole").add(option);
        setRole()
    }

    function delChecked(sNode) {
        var index = sNode.selectedIndex;
        var option = sNode.options[index];
        option.selected = false;
        document.getElementById("allRole").add(option);
        setRole()
    }

    function setRole() {
        var groupId = "${groupId!}";
        var roleIds = "";
        var checkedRole = document.getElementById("checkedRole");
        var length = checkedRole.length;
        for (var i = 0; i < length; i++) {
            roleIds += checkedRole.options[i].value + ",";
        }
        var result = false;
        post("/b/group/setRole", {"id": groupId, "roleIds": roleIds}, function (res) {
            if (!res.success) {
                msg("操作失败")
                return
            }
            msg("设置成功")
            result = true;
        }, function () {
            systemErr();
        })
    }
</script>
<div class="modal-body">
    <div class="row">
        <div class="col-md-6">
            <div class="panel-heading">
                <h4 class="panel-title">
                    未选角色
                </h4>
            </div>
            <div class="panel-body">
                <select id="allRole" multiple size="18" class="form-control" ondblclick="addChecked(this);">
                    <% for(role in noCheckedList){ %>
                    <option value='${role.id!}'>${role.name!}</option>
                    <% } %>
                </select>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel-heading">
                <h4 class="panel-title">
                    已选角色
                </h4>
            </div>
            <div class="panel-body">
                <select id="checkedRole" multiple size="18" class="form-control" ondblclick="delChecked(this);">
                    <% for(role in checkedList){ %>
                    <option value='${role.id!}'>${role.name!}</option>
                    <% } %>
                </select>
            </div>
        </div>
    </div>
</div>